# Maintainer: Andrea Zagli <andrea.zagli.free@gmail.com>

_realname=goocanvas
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.0.4
pkgrel=3
arch=('any')
pkgdesc="Canvas widget for GTK+ that uses the Cairo 2D library (mingw-w64)"
license=("LGPL 2")
url="https://www.gnome.org"
depends=("${MINGW_PACKAGE_PREFIX}-gtk3")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-python2"
             "${MINGW_PACKAGE_PREFIX}-python3"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc"
             "make"
             "libtool"
             "automake-wrapper"
             "autoconf"
             "gettext"
             "libintl"
             "patch")
options=('strip' '!debug' 'staticlibs')
source=(https://download.gnome.org/sources/${_realname}/${pkgver:0:3}/${_realname}-${pkgver}.tar.xz
             001-convert-python-path-to-unix.patch
             002-fix-introspection.patch)
sha256sums=('c728e2b7d4425ae81b54e1e07a3d3c8a4bd6377a63cffa43006045bceaa92e90'
            '9740420cd1e2cf2362e5170ead007685686656e3764c905f7b0313b62ed41298'
            '2dd3aa690c179b74c3c443732d43672a23271589086c248325e4a762560584f2')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-convert-python-path-to-unix.patch
  patch -p1 -i ${srcdir}/002-fix-introspection.patch
  autoreconf -fi
  cp -r ${srcdir}/${_realname}-${pkgver} ${srcdir}/${MINGW_CHOST}-${_realname}-python2
  cp -r ${srcdir}/${_realname}-${pkgver} ${srcdir}/${MINGW_CHOST}-${_realname}-python3
}

build() {
  # we must build things twice
  for _python in python{2,3}; do
    cd ${srcdir}/${MINGW_CHOST}-${_realname}-${_python}

    mkdir -p docs/html
    cp -rf ../${_realname}-${pkgver}/docs/html/* docs/html

    # an argument passed to glib-mkenums starts with a c++ comment
    export MSYS2_ARG_CONV_EXCL="/*"
    export CC=gcc
    ./configure \
      --host=${MINGW_CHOST} \
      --target=${MINGW_CHOST} \
      --build=${MINGW_CHOST} \
      --prefix=${MINGW_PREFIX} \
      --libexecdir=${MINGW_PREFIX}/lib \
      --enable-introspection=yes \
      PYTHON=${MINGW_PREFIX}/bin/${_python}
    make
  done
}

package() {
  for _python in python{2,3}; do
    cd ${srcdir}/${MINGW_CHOST}-${_realname}-${_python}
    make DESTDIR=${pkgdir} install
  done
}
